#include "init.hpp"
#include <fstream>

extern MemControl membus;
extern Reg<uint64_t> iregs;
extern Reg<uint64_t> sregs;
extern Reg<uint64_t> IMMs;
extern uint8_t *memory;
static uint64_t count = 0;

void init(const size_t size)
{
	memory = new uint8_t[size];
	iregs[Stack] = 0xf000;
	sregs[Status] = 0x01000401;
}
void shutdown()
{
	delete[] memory;
	sregs.~Reg();
	iregs.~Reg();
	IMMs.~Reg();
	membus.~MemControl();
}
void loadMemory(const char *filename, const size_t size)
{ // 读取BIOS文件
	std::ifstream file(filename, std::ios::binary);
	file.read((char *)memory, size);
	file.close();
}
void loadDevice(const char *filename, const TYPE type)
{
	membus.mount(filename, count, type);
	count += 1;
}